#include "smartwidget.h"
#include "ui_smartwidget.h"
#include "controlwidget.h"


#define w 174
#define h 50

smartwidget::smartwidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::smartwidget)
{
    ui->setupUi(this);

    this->setMaximumSize(1070,730);
    this->setMinimumSize(1070,730);

    QPalette pal;
    pal.setBrush(QPalette::Background,QBrush(QPixmap(QString(":/new/prefix1/images/test.png")).scaled(1070,730)));
    this->setPalette(pal);

    //窗帘右开
    curtainRightOn = new QPushButton(this);
    curtainRightOn->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/chuanglianyoukai.png")).scaled(w,h)));
    curtainRightOn->setIconSize(QSize(w,h));
    curtainRightOn->setFixedSize(w,h);
    //窗帘右关
    curtainRightOff = new QPushButton(this);
    curtainRightOff->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/chuanglianyouguan.png")).scaled(w,h)));
    curtainRightOff->setIconSize(QSize(w,h));
    curtainRightOff->setFixedSize(w,h);
    //窗帘左开
    curtainLeftOn = new QPushButton(this);
    curtainLeftOn->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/chuanglianzuokai.png")).scaled(w,h)));
    curtainLeftOn->setIconSize(QSize(w,h));
    curtainLeftOn->setFixedSize(w,h);
    //窗帘左关
    curtainLeftOff = new QPushButton(this);
    curtainLeftOff->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/chuanglianzuoguan.png")).scaled(w,h)));
    curtainLeftOff->setIconSize(QSize(w,h));
    curtainLeftOff->setFixedSize(w,h);
    //报警器开
    alarmOn= new QPushButton(this);
    alarmOn->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/dakaibaojingqi.png")).scaled(w,h)));
    alarmOn->setIconSize(QSize(w,h));
    alarmOn->setFixedSize(w,h);
    //报警器关
    alarmOff = new QPushButton(this);
    alarmOff->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/guanbibaojingqi.png")).scaled(w,h)));
    alarmOff->setIconSize(QSize(w,h));
    alarmOff->setFixedSize(w,h);
    //灯1
    light1 = new QPushButton(this);
    light1->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/dengyi.png")).scaled(w,h)));
    light1->setIconSize(QSize(w,h));
    light1->setFixedSize(w,h);
    //灯2
    light2 = new QPushButton(this);
    light2->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/denger.png")).scaled(w,h)));
    light2->setIconSize(QSize(w,h));
    light2->setFixedSize(w,h);
    //灯3
    light3 = new QPushButton(this);
    light3->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/dengsan.png")).scaled(w,h)));
    light3->setIconSize(QSize(w,h));
    light3->setFixedSize(w,h);
    //灯4
    light4 = new QPushButton(this);
    light4->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/dengsi.png")).scaled(w,h)));
    light4->setIconSize(QSize(w,h));
    light4->setFixedSize(w,h);
    //客厅空调1
    livingRoomAir1 = new QPushButton(this);
    livingRoomAir1->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/kongtiaoyi.png")).scaled(348,150)));
    livingRoomAir1->setIconSize(QSize(348,150));
    livingRoomAir1->setFixedSize(348,150);
    //客厅空调2
    livingRoomAir2 = new QPushButton(this);
    livingRoomAir2->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/kongtiaoer.png")).scaled(348,150)));
    livingRoomAir2->setIconSize(QSize(348,150));
    livingRoomAir2->setFixedSize(348,150);
    //屏幕
    screen = new QPushButton(this);
    screen->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/ceshineirong.jpg")).scaled(522,280)));
    screen->setIconSize(QSize(522,280));
    screen->setFixedSize(522,280);
    //键控
    jiankong = new QPushButton(this);
    jiankong->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/jiankonganniubeijing.png")).scaled(147,150)));
    jiankong->setIconSize(QSize(174,150));
    jiankong->setFixedSize(174,150);

    up = new QPushButton(this);
    up->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/xiangshang.png")).scaled(28,42)));
    up->setIconSize(QSize(28,42));
    up->setFixedSize(28,42);
    down = new QPushButton(this);
    down->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/xiangxia.png")).scaled(28,42)));
    down->setIconSize(QSize(28,42));
    down->setFixedSize(28,42);
    left = new QPushButton(this);
    left->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/xiangzuo.png")).scaled(42,28)));
    left->setIconSize(QSize(42,28));
    left->setFixedSize(42,28);
    right = new QPushButton(this);
    right->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/xiangyou.png")).scaled(42,28)));
    right->setIconSize(QSize(42,28));
    right->setFixedSize(42,28);
    start = new QPushButton(this);
    start->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/start.png")).scaled(55,55)));
    start->setIconSize(QSize(55,55));
    start->setFixedSize(55,55);


    uplayout = new QHBoxLayout;
    uplayout->addStretch();
    uplayout->addWidget(up);
    uplayout->addStretch();

    startlayout = new QHBoxLayout;
    startlayout->addStretch();
    startlayout->addWidget(left);
    startlayout->addWidget(start);
    startlayout->addWidget(right);
    startlayout->addStretch();

    downlayout = new QHBoxLayout;
    downlayout->addStretch();
    downlayout->addWidget(down);
    downlayout->addStretch();

    jiankongmain = new QVBoxLayout;
    jiankongmain->addLayout(uplayout);
    jiankongmain->addLayout(startlayout);
    jiankongmain->addLayout(downlayout);


    jiankonglayout = new QGridLayout;
    jiankonglayout->addWidget(jiankong,0,0,3,3);
    jiankonglayout->addLayout(jiankongmain,0,0,3,3);

    /*
    jiankonglayout->addWidget(up,0,1,1,1);
    jiankonglayout->addWidget(down,2,1,1,1);
    jiankonglayout->addWidget(left,1,0,1,1);
    jiankonglayout->addWidget(right,1,2,1,1);
    jiankonglayout->addWidget(start,1,1,1,1);
*/

    //返回
    back = new QPushButton(this);
    back->setIcon(QIcon(QPixmap(QString(":/new/prefix1/images/back2.png")).scaled(50,30)));
    back->setIconSize(QSize(50,30));
    back->setFixedSize(50,30);

    mainlayout = new QGridLayout;
    mainlayout->addWidget(curtainRightOn,0,1,1,1);
    mainlayout->addWidget(curtainRightOff,1,1,1,1);
    mainlayout->addWidget(curtainLeftOn,2,1,1,1);
    mainlayout->addWidget(curtainLeftOff,3,1,1,1);
    mainlayout->addWidget(alarmOn,4,1,1,1);
    mainlayout->addWidget(livingRoomAir1,5,1,1,2);

    mainlayout->addWidget(screen,0,2,5,3);
    mainlayout->addLayout(jiankonglayout,5,3,1,1);

    mainlayout->addWidget(light1,0,5,1,1);
    mainlayout->addWidget(light2,1,5,1,1);
    mainlayout->addWidget(light3,2,5,1,1);
    mainlayout->addWidget(light4,3,5,1,1);
    mainlayout->addWidget(alarmOff,4,5,1,1);
    mainlayout->addWidget(livingRoomAir2,5,4,1,2);


    mainlayout->setHorizontalSpacing(5);
    mainlayout->setVerticalSpacing(5);
    mainlayout->setContentsMargins(100,100,100,200);
    this->setLayout(mainlayout);

    connect(back,SIGNAL(clicked(bool)),this,SLOT(backSlot()));

}

smartwidget::~smartwidget()
{
    delete ui;
}

void smartwidget::backSlot()
{
    this->close();
    controlWidget *r = new controlWidget();
    r->show();
}
